package com.car.service.Impl;

import com.car.exception.CustomException;
import com.car.service.LicenseService;
import com.car.util.FileUtil;
import com.car.util.LicensePlate;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @author 党怡承
 * @since 2021-08-09
 */
@Service
public class LicenseServiceImpl implements LicenseService {
  @Override
  public String licensePlate(MultipartFile multipartFile) {
    try {
      File file = FileUtil.uploadFile(multipartFile);
      String result = LicensePlate.licensePlate(file.getAbsolutePath());
      if (result != null) {
        return result;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    throw new CustomException(20001,"No license plate recognition result set is obtained");
  }
}
